package com.example.seckill.dao;

import com.example.seckill.entity.SeckillGoods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface SeckillGoodsMapper {
    
    @Select("SELECT * FROM seckill_goods")
    List<SeckillGoods> selectList();
    
    @Select("SELECT * FROM seckill_goods WHERE id = #{id}")
    SeckillGoods selectById(@Param("id") Long id);

    @Update("UPDATE seckill_goods SET stock = stock - 1 WHERE id = #{goodsId} AND stock > 0")
    int reduceStock(@Param("goodsId") Long goodsId);

    @Select("<script>" +
            "SELECT * FROM seckill_goods WHERE id IN " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<SeckillGoods> selectByIds(@Param("ids") List<Long> ids);
} 